package com.lin.mybatis.dao;


import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.lin.mybatis.IgnoreTenant;
import com.lin.mybatis.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.cursor.Cursor;

import java.util.List;

/**
 * 作者：lin
 * 功能：
 * 时间：2023/3/8 16:22
 */
@Mapper
public interface UserDao extends RootMapper<User> {

    @Select("select * from sys_user limit #{pageNum},#{pageSize}")
    List<User> page(@Param("pageNum") int page, @Param("pageSize") int pageSize);

    @Select("select * from sys_user where id >= #{pageNum} limit #{pageNum},#{pageSize}")
    List<User> pageIdOptimize(@Param("pageNum") int page, @Param("pageSize") int pageSize);

    @Select("SELECT * FROM sys_user JOIN (SELECT id FROM sys_user LIMIT #{pageNum},#{pageSize}) b on sys_user.id = b.id;")
    List<User> pageChildOptimize(@Param("pageNum") int page, @Param("pageSize") int pageSize);

    @Select("select * from sys_user limit #{pageNum},#{pageSize}")
    Cursor<User> pagePipleOptimize(@Param("pageNum") int page, @Param("pageSize") int pageSize);

    @IgnoreTenant
    default User getByIdDefault(Integer id) {
        return selectById(id);
    }

    @InterceptorIgnore(tenantLine = "true") // 忽略租户条件拼接
    @Select("select * from sys_user where id = #{id}")
    User getByIdInter(Integer id);
}
